from stack import Stack


def par_checker(symbol_string):

    s = Stack()
    balanced = True  # balanced是标识符

    index = 0   # index是计数器
    while index < len(symbol_string) and balanced:
        # 取出括号
        symbol = symbol_string[index]

        # 如果是左括号，那么就将左括号加入栈中
        if symbol == '(':
            s.push(symbol)

        # 如果是右括号，那么当栈是空则表示右括号多了，左右括号不匹配，标识符标记为False返回结果；
        # 如果栈不是空的，则将栈顶pop
        else:
            if s.is_empty():
                balanced = False
            else:
                s.pop()
        index += 1

    # 如果遍历结果的栈为空，表明左右括号的数量是一致的
    if balanced and s.is_empty():
        return True
    else:
        return False


def test(symbol_string):
    s = Stack()
    status = True

    index = 0
    while index < len(symbol_string) and status:
        symbol = symbol_string[index]

        if symbol == '(':
            s.push(symbol)
        else:
            if s.is_empty():
                status = False
            else:
                s.pop()

        index += 1

    if status and s.is_empty():
        return True
    else:
        return False


if __name__ == '__main__':
    s = '(((())))'
    print(test(s))